﻿using huqiang.Data;
using huqiang.Data.Extension;
using System;
using UnityEngine;

namespace huqiang.Core.UIData
{
    public class ABMission
    {
        public string url;
        public string assetsName;
        public event Action<HSprite> CallBack;
        public AssetBundleCreateRequest createRequest;
        public void Compelete(AsyncOperation operation)
        {
            var ab = createRequest.assetBundle;
            Texture2D t2d =  ab.LoadAsset<Texture2D>(assetsName);
            var ta = ab.LoadAsset<TextAsset>(assetsName+"_layout");
            if(ta!=null)
            {
                string[] lines = ta.text.Split('\n');
                for (int i = 0; i < lines.Length; i++)
                {
                    string str = lines[i];
                    int index = str.IndexOf(':');
                    string name = str.Substring(0, index);
                    int end = str.IndexOf(',', index);
                    if (end > 0)
                    {
                        float x = str.ParseFloat(index + 1, end);
                        index = end;
                        end = str.IndexOf(',', index);
                        float y = str.ParseFloat(index + 1, end);
                        index = end;
                        end = str.IndexOf(',', index);
                        float w = str.ParseFloat(index + 1, end);
                        index = end;
                        end = str.Length;
                        float h = str.ParseFloat(index + 1, end);
                    }
                }
            }
        }
    }
}
